package com.ry.est.config;

import com.ry.est.annotations.TokenUserHandlerMethodArgumentResolver;
import com.ry.est.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class EstWebMvcConfig implements WebMvcConfigurer {
    /**
     * 添加自定义的参数解析器
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(tokenUserHandlerMethodArgumentResolver());
    }

    @Autowired
    private TokenService tokenService;

    @Bean
    public TokenUserHandlerMethodArgumentResolver tokenUserHandlerMethodArgumentResolver(){
        TokenUserHandlerMethodArgumentResolver tokenUserHandlerMethodArgumentResolver = new TokenUserHandlerMethodArgumentResolver();
        tokenUserHandlerMethodArgumentResolver.setTokenService(tokenService);

        return tokenUserHandlerMethodArgumentResolver;
    }
}
